package com.xhui.vimarket.common.exception;

import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;

/**
 */

public class BaseException extends Exception {
    /**
     * serialVersionUID long.
     */
    private static final long serialVersionUID   = 5232985317228036604L;
    
    /**
     * int MANUAL_CLOSE.
     */
    public static final int   MANUAL_CLOSE       = -1;
    
    /**
     * int TEN_SENCONDS_CLOSE.
     */
    public static final int   TEN_SENCONDS_CLOSE = 10;
    
    /**
     * int NEW_OPEN.
     */
    public static final int   NEW_OPEN           = 1;
    
    /**
     * int PRESENT_OPEN.
     */
    public static final int   PRESENT_OPEN       = 0;
    
    /**
     * int PARENT_OPEN.
     */
    public static final int   PARENT_OPEN        = -1;
    
    /**
     * int ERROR_TYPE.
     */
    public static final int   ERROR_TYPE         = -1;
    
    /**
     * int INFO_TYPE.
     */
    public static final int   INFO_TYPE          = 1;
    
    /**
     * int WARN_TYPE.
     */
    public static final int   WARN_TYPE          = 0;
    
    /**
     * Throwable rootCause.
     */
    protected Throwable       rootCause          = null;
    
    private final Collection  exceptions         = new ArrayList();
    
    private Object            errObj             = null;
    
    private String            messageKey         = null;
    
    private int               exceptionType      = BaseException.INFO_TYPE;
    
    private int               openType           = BaseException.PRESENT_OPEN; // web打开异常页面的方式
                                                                               
    private int               closeType          = 5;                         // 当前窗口的关闭时显示的时间
                                                                               
    private Object[]          messageArgs        = null;
    
    private String            plusInfo           = null;
    
    /**
     * @author: wuq
     * @修改记录： ==============================================================<br>
     *        日期:2007-9-14 wuq 创建方法，并实现其功能
     *        ==============================================================<br>
     */
    public BaseException() {
        super();
    }
    
    /**
     * @param aCause
     *            参数
     */
    public BaseException(final Throwable aCause) {
        this.rootCause = aCause;
    }
    
    /**
     * @return Collection
     * @author: wuq
     */
    public Collection getCollection() {
        return this.exceptions;
    }
    
    /**
     * @param ex
     *            参数
     * @author: wuq
     * @修改记录： ==============================================================<br>
     *        日期:2007-9-14 wuq 创建方法，并实现其功能
     *        ==============================================================<br>
     */
    public void addException(final BaseException ex) {
        this.exceptions.add(ex);
    }
    
    /**
     * @param anExceptionType
     *            参数
     */
    public void setExceptionType(final int anExceptionType) {
        this.exceptionType = anExceptionType;
    }
    
    /**
     * @return int
     */
    public int getExceptionType() {
        return this.exceptionType;
    }
    
    /**
     * @param anOpenType
     */
    
    public void setOpenType(final int anOpenType) {
        this.openType = anOpenType;
    }
    
    /**
     * @return int
     */
    public int getOpenType() {
        return this.openType;
    }
    
    /**
     * @param aCloseType
     *            int
     */
    
    public void setCloseType(final int aCloseType) {
        this.closeType = aCloseType;
    }
    
    /**
     * @return int
     * 
     */
    public int getCloseType() {
        return this.closeType;
    }
    
    /**
     * @param key
     *            String
     */
    public void setMessageKey(final String key) {
        this.messageKey = key;
    }
    
    /**
     * @return String
     */
    public String getMessageKey() {
        return this.messageKey;
    }
    
    /**
     * @param args
     *            Object[]
     */
    public void setMessageArgs(final Object[] args) {
        this.messageArgs = args;
    }
    
    /**
     * @return Object[]
     */
    public Object[] getMessageArgs() {
        return this.messageArgs;
    }
    
    /**
     * @param anException
     *            Throwable
     */
    public void setRootCause(final Throwable anException) {
        this.rootCause = anException;
    }
    
    /**
     * @return Throwable
     */
    public Throwable getRootCause() {
        return this.rootCause;
    }
    
    /**
     * @param plusInfo
     *            String
     */
    public void setPlusInfo(final String plusInfo) {
        this.plusInfo = plusInfo;
    }
    
    /**
     * @return String
     */
    public String getPlusInfo() {
        return this.plusInfo;
    }
    
    /**
     */
    @Override
    public void printStackTrace() {
        this.printStackTrace(System.err);
    }
    
    /**
     * @param outStream
     *            PrintStream
     */
    @Override
    public void printStackTrace(final PrintStream outStream) {
        this.printStackTrace(new PrintWriter(outStream));
    }
    
    /**
     * @param writer
     *            PrintWriter
     */
    @Override
    public void printStackTrace(final PrintWriter writer) {
        super.printStackTrace(writer);
        if (this.getRootCause() != null) {
            this.getRootCause().printStackTrace(writer);
        }
        writer.flush();
    }
    
    /**
     * 传递错误对象信息，如Map对象等.

     */
    public Object getErrObj() {
        return this.errObj;
    }
    
    /**
     * 传递错误对象信息，如Map对象等.
     */
    public void setErrObj(final Object errObj) {
        this.errObj = errObj;
    }
}
